from scipy import integrate
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

# 数值积分，求解圆周率
"""
半径为1的原方程：x^2+y^2=1

"""
x = np.linspace(-1, 1, 100)
y = (1 - x ** 2) ** 0.5
plt.plot(x, y, x, -y)
plt.axis('equal')  # axis()设置坐标轴，equal：x,y轴刻度等长
plt.show()
f = lambda x: (1 - x ** 2) ** 0.5
half_pi, deviation = integrate.quad(f, -1, 1)# 得到的是一个元组(积分,误差)
print(half_pi*2, deviation)
